local skill = fk.CreateSkill{
  name = "tea__fenwu",
}
---@type TrigSkelSpec<MoveCardsFunc>
local fenwu = {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skill.name) then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard and move.from then
          local cids = {}
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(cids, info.cardId)
          end
          if #cids > 1 then
            event:setCostData(self, {
              from = move.from,
              cids = cids,
            })
            return not move.from:isNude() and player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).from
    local cids = event:getCostData(self).cids
    local r_cards = {}
    for i = 1, 2 do
      if to:isNude() then break end
      local r_cid = room:askToCards(to, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = skill.name,
        cancelable = false,
        prompt = "#tea__fenwu-choose"
      })
      if #r_cid > 0 then
        table.insert(r_cards, r_cid[1])
        room:recastCard(r_cid, to, self.name)
      end
    end
    if #r_cards == 2 then
      if Fk:getCardById(r_cards[1]).color == Fk:getCardById(r_cards[2]).color then
        cids = table.filter(cids, function(id)
          return room:getCardArea(id) == Card.DiscardPile
        end)
        if #cids > 0 then
          local choose_cid = room:askToCards(to, {
            min_num = 1,
            max_num = 1,
            include_equip = false,
            skill_name = skill.name,
            pattern = tostring( Exppattern{ id = cids } ),
            prompt = "#tea__fenwu-obtain",
            expand_pile = cids,
          })
          if #choose_cid > 0 then
            room:obtainCard(to, choose_cid, true, fk.ReasonPrey)
          end
        end
      end
    end
  end,
}
skill:addEffect(fk.AfterCardsMove, fenwu)
return skill